package com.vcg.community.consumer;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import test.dubboConsumer;
import vc.bean.SearchHits;
import vc.dubbo.result.DubboResult;
import vc.search.service.ResourceService;
import vc.search.service.SearchService;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.vcg.community.model.Resource;

public class SearchConsumer {
	public DubboResult<String> doSearchIndex(Resource r){
		String config = SearchConsumer.class.getPackage().getName().replace('.', '/') + "/" + "SearchConsumer.xml";
		
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
        context.start();
 
        /*
        SearchService searchService = (SearchService)context.getBean("searchService"); // 获取远程服务代理
		String jsonRSString = JSON.toJSONString(r);
        JSONObject jsonRSObject = JSON.parseObject(jsonRSString);  
        String strResult=searchService.index("index", "image",jsonRSObject );
        return strResult;
        */	
        ResourceService searchService = (ResourceService)context.getBean("resourceService"); // 获取远程服务代理
		String jsonRSString = JSON.toJSONString(r);
        JSONObject jsonRSObject = JSON.parseObject(jsonRSString);  
        DubboResult<String> strResult=searchService.index(r.getResourceId(),jsonRSObject );
        return strResult;
 	}

}
